<?php


class Clicklogs extends AppModel
{
	var $name='Clicklogs';
	function getLogCount($pid){
		$pid = intval($pid);
		return $this->findCount("product_id={$pid}");
	}
	function getLog($pid,$start,$count){
		$pid = intval($pid);
		$start = intval($start);
		$count = intval($count);		
		$sql = "SELECT * FROM `g_clicklogs` left join `g_users` on `g_users`.`g_id` = `g_clicklogs`.`user_id` where `product_id`={$pid} order by seqid desc limit $start,$count";
		$data = $this->query($sql);
		return $data;
	}
	function getLogAll($start,$count){
		$pid = intval($pid);
		$start = intval($start);
		$count = intval($count);		
	    $time_start = empty($_REQUEST['from'])?0:intval($_REQUEST['from']);
		$time_end = empty($_REQUEST['end'])?0:intval($_REQUEST['end']);
		if (!empty($time_start) && !empty($time_end)){
		    $t_s = date('Y-m-d',$time_start);
		    $t_e = date('Y-m-d',$time_end);
		    $where_date = " `g_clicklogs`.`time` >'$t_s' and `g_clicklogs`.`time` <'$t_e' ";
		}else {
		    $where_date = '';
		}
		
		$sql = "SELECT g_clicklogs.seqid,g_clicklogs.time,g_users.g_uid ,g_users.g_name ,g_products.g_id,g_products.g_name FROM `g_clicklogs` left join `g_users` on `g_users`.`g_id` = `g_clicklogs`.`user_id` left join `g_products` on `g_products`.`g_id` = `g_clicklogs`.`product_id`  where 1 and $where_date order by seqid limit $start,$count";
		$data = $this->query($sql);
		return $data;
	}

	
}
?>